@use "sass:math";

.sidebar {
  display: flex;
  flex-flow: column;
}

.sidebar__header {
  padding: #{math.div(8, $base-font-size)}rem #{math.div(12, $base-font-size)}rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: #{math.div(29, $base-font-size)}rem;
  position: relative;
}

.sidebar__title {
  font-size: #{math.div(16, $base-font-size)}rem;
  font-weight: 500;
  display: inline-block;
  .sidebar--contracted & {
    display: none;
  }
  white-space: nowrap;
  overflow: hidden;
}

.sidebar__add {
  padding: #{math.div(2, $base-font-size)}rem;
  display: flex;
  align-items: center;
  justify-content: center;
  & svg {
    width: #{math.div(18, $base-font-size)}rem;
    height: #{math.div(18, $base-font-size)}rem;
  }
  @include themify() {
    background-color: getThemifyVariable('ide-border-color');
  }

  .sidebar--contracted & {
    display: none;
  }
}

.sidebar__file-list {
  @include themify() {
    border-color: getThemifyVariable('ide-border-color')
  }
  border-top: 1px solid;
  .sidebar--contracted & {
    display: none;
  }
}

.sidebar__root-item {
  position: relative;
  overflow-y: auto;
  padding-top: #{math.div(6, $base-font-size)}rem;
  flex: 1 1 auto;
  @media (min-width: 770px) {
    @include themify() {
      border-top: 1px solid map-get($theme-map, 'ide-border-color');
    }
  }
  .sidebar--contracted & {
    border: none;
  }
}

.file-item__children {
  display: flex;
  flex-direction: column;
  gap: #{math.div(4, $base-font-size)}rem;
}

.sidebar__file-item {
  font-size: #{math.div(12, $base-font-size)}rem;
  cursor: pointer;
  position: relative;
  @include themify() {
    color: map-get($theme-map, 'primary-text-color');
    // TODO get this to not affect parent, need to move it into JS
    &:hover:not(.sidebar__file-item--selected) > .file-item__content {
      background-color: map-get($theme-map, 'file-hover-color');
    }
  }
}

.sidebar__file-item--folder {
  z-index: 1;
  display: flex;
  align-items: center;
  > button {
    padding-left: #{math.div(1, $base-font-size)}rem;
  }
}

// to indent each row in the file tree
// not sure how to do this in a better way
// it won't work if the file tree is too nested
.file-item__spacer {
  flex-shrink: 0;
  .sidebar__file-item & {
    width: #{math.div(19, $base-font-size)}rem;
    .sidebar__file-item & {
      width: #{math.div(39, $base-font-size)}rem;
      .sidebar__file-item & {
        width: #{math.div(59, $base-font-size)}rem;
        .sidebar__file-item & {
          width: #{math.div(79, $base-font-size)}rem;
          .sidebar__file-item & {
            width: #{math.div(99, $base-font-size)}rem;
          }
        }
      }
    }
  }
}

.file-item__content {
  display: flex;
  position: relative;
  .sidebar__file-item--selected > & {
    @include themify() {
      background-color: map-get($theme-map, 'file-selected-color');
    }
  }
  .sidebar--contracted & {
    display: none;
  }
}

.sidebar__file-item-name--ellipsis {
  overflow-x: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  min-width: #{math.div(7, $base-font-size)}rem;
  white-space: pre;
}

.sidebar__file-item-name-text {
  display: flex;
  width: 100%;
  overflow: hidden;
  min-width: #{math.div(50, $base-font-size)}rem;
  white-space: nowrap;
  text-align: left;
}

.sidebar__file-item-name {
  padding: #{math.div(4, $base-font-size)}rem 0;
  padding-right: #{math.div(25, $base-font-size)}rem;
  font-family: Inconsolata, monospace;
  font-size: #{math.div(15, $base-font-size)}rem;
  overflow: hidden;
  .sidebar__file-item--editing & {
    display: none;
  }
  &:before {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    content: '';
    width: 100%;
  }
  @include themify() {
    color: map-get($theme-map, 'primary-text-color');
  }
}

.sidebar__file-item-show-options {
  width: #{math.div(20, $base-font-size)}rem;
  height: #{math.div(20, $base-font-size)}rem;
  @include icon();
  @include themify() {
    margin-right: #{math.div(5, $base-font-size)}rem;
  }
  display: none;
  position: absolute;
  right: 0;
  .sidebar__file-item--selected > .file-item__content & {
    display: inline-block;
    .sidebar--cant-edit & {
      display: none;
    }
  }
  .sidebar__file-item:hover > .file-item__content & {
    display: inline-block;
    .sidebar--cant-edit & {
      display: none;
    }
  }
  & svg {
    width: #{math.div(10, $base-font-size)}rem;
  }
  .sidebar__file-item--open > .file-item__content & {
    display: inline-block;
  }
}

.sidebar__file-item-options {
  @extend %dropdown-open-right;
  display: none;
  width: 100%;
  max-width: #{math.div(180, $base-font-size)}rem;
  .sidebar__file-item--open > .file-item__content & {
    display: flex;
  }
}

.sidebar__file-item-input {
  display: none;
  padding: 0;
  border: 0;
  width: calc(100% - #{math.div(63, $base-font-size)}rem);
  font-family: Inconsolata, monospace;
  font-size: #{math.div(14, $base-font-size)}rem;
  .sidebar__file-item--editing & {
    display: inline-block;
  }
}

.sidebar__expand,
.sidebar__contract {
  @include icon();
  position: absolute;
  top: #{math.div(2, $base-font-size)}rem;
  left: #{math.div(0, $base-font-size)}rem;
  height: #{math.div(25, $base-font-size)}rem;
  width: #{math.div(49, $base-font-size)}rem;
  border-radius: 2px;
  display: flex;
  justify-content: center;
  align-items: center;
  @include themify() {
    background-color: getThemifyVariable("toolbar-button-background-color");
    & polygon, & path {
      fill: getThemifyVariable("toolbar-button-color");
    }
    &:hover {
      background-color: getThemifyVariable("button-background-hover-color");
      & polygon, & path {
        fill: getThemifyVariable("button-hover-color");
      }
    }
  }
}

.sidebar__expand {
  display: none;
  &:hover {
    cursor: e-resize;
  }
  .sidebar--contracted & {
    display: flex;
  }
}

.sidebar__contract {
  &:hover {
    cursor: w-resize;
  }
  .sidebar--contracted & {
    display: none;
  }
}

.sidebar__icons {
  display: flex;
  align-items: center;
  height: 100%;
  .sidebar--cant-edit & {
    display: none;
  }
}

.sidebar__folder-icon {
  padding: #{math.div(4, $base-font-size)}rem 0;
  margin-right: #{math.div(5, $base-font-size)}rem;
  & path {
    @include themify() {
      fill: map-get($theme-map, 'primary-text-color');
    }
  }
  & svg {
    width: #{math.div(10, $base-font-size)}rem;
  }
}

.sidebar__file-item-icon {
  margin-right: #{math.div(5, $base-font-size)}rem;
  display: flex;
  align-items: center;
  & path {
    @include themify() {
      fill: getThemifyVariable('secondary-text-color');
    }
  }
  background-color: transparent;
  border: none;
}

.sidebar__file-item-closed {
  @extend .sidebar__file-item-icon;
  display: none;
  .sidebar__file-item--closed & {
    display: inline-block;
  }
}

.sidebar__file-item-open {
  @extend .sidebar__file-item-icon;
  display: inline-block;
  .sidebar__file-item--closed & {
    display: none;
  }
}

.sidebar__file-item--closed .file-item__children {
  display: none;
}

.sidebar__project-options {
  @extend %dropdown-open-right;
  display: none;
  width: 100%;
  max-width: #{math.div(180, $base-font-size)}rem;
  .sidebar--project-options & {
    display: flex;
  }
}
